#include <iostream>
#include <string>
using namespace std;

int main()
{
    int m, n;
    cin >> m >> n;
    string mod = "0123456789ABCDEF";
    if(m == 0){
        printf("%d", 0);
        return 0;
    }
    string s;
    while(m){
        if(m < 0){
            m = -m;
            cout << '-';
        }
        s = mod[m%n] + s;
        m /= n;
    }
    cout << s;
    
    return 0;
}
